use crate::controller::{user, Context};
use warp::Filter;

pub async fn init() {
    // user 模块
    // let user_filter = warp::path("User");
    // let user_filter = user_filter
    //     .and(Context::api(warp::post(), "Login", user::login))
    //     .or(user_filter.and(Context::api(warp::post(), "Register", user::register)))
    //     .or(user_filter.and(Context::api(
    //         warp::get(),
    //         "get_kl",
    //         user::get_kl,
    //     )));

    //查询模块 qot
    let qot_filter = warp::path("qot");
    let qot_filter = qot_filter
        .and(Context::api(warp::get(), "qot_sub", user::qot_sub))
        .or(qot_filter.and(Context::api(warp::get(), "qot_regqotpush", user::qot_reg_qot_push)))
        .or(qot_filter.and(Context::api(warp::get(), "get_kl", user::get_kl)))
        ;

    //交易模块 trd
    // let trd_filter = warp::path("qot");
    // let trd_filter = trd_filter
    //     .and(Context::api(warp::get(), "trd_getfunds", user::trd_getfunds))
    //     .or(trd_filter.and(Context::api(warp::get(), "trd_placeorder", user::trd_placeorder)))
    //     .or(trd_filter.and(Context::api(warp::get(), "trd_getorderfilllist", user::trd_getorderfilllist)))
    //     ;

    let filter = warp::path("v1")
        .and(qot_filter)
        .recover(Context::handle_rejection)
        //.with(warp::cors().allow_header("token").expose_header("token").allow_any_origin());
        .with(warp::wrap_fn(Context::request_wrapper));

    warp::serve(filter).run(([127, 0, 0, 1], 3030)).await
}
